const deepCopy = function(target) {
  let result;
  // 判断是否是引用数据类型
  if (typeof target === "object") {
    if (Array.isArray(target)) {
      result = [];
      for (let i = 0; i < target.length; i++) {
        result.push(deepCopy(target[i]));
      }
    } else if (target.constructor === RegExp) {
      result = target;
    } else if (target === null) {
      result = null;
    } else {
      //以上条件都不成立 普通对象
      result = {};
      for (let i in target) {
        result = deepCopy(target[i]);
      }
    }
  }
  // 普通类型
  else {
    result = target;
  }
  // 对上层返回拷贝结果
  return result;
};

export { deepCopy };
